import { useRequest } from '@/common/composables/useRequest'
import {
  UserApi,
  VerifyApi,
  MailboxApi,
  ElverifyApi,
  ELLoginApi,
  PersonalDataApi,
} from '@/common/constants/service-api'
import type { ModificationMaterials } from '../types/user-type'
/**
 * 根据用户id获取用户信息
 * @returns
 */
export const getUserInfoByIdService = (token: string) => {
  return useRequest({
    url: UserApi.GET_USERINFO[1],
    options: {
      method: UserApi.GET_USERINFO[0],
      headers: {
        Authorization: `Bearer ${token}`, // 添加 Authorization 请求头
      },
    },
  })
}

/**
 * 发送邮箱验证码
 * @returns
 */
export const getEmailVerificationCode = (email: string) => {
  return useRequest({
    url: VerifyApi.VERIFY_QQ[1],
    options: {
      method: VerifyApi.VERIFY_QQ[0],
      body: JSON.stringify({ email }), // 请求体，传递 email
    },
  })
}

/**
 * 邮箱验证码注册
 * @returns
 */
export const getRegisterWithEmail = (email: string, code: string) => {
  return useRequest({
    url: MailboxApi.MAILBOX_QQ[1],
    options: {
      method: MailboxApi.MAILBOX_QQ[0],
      body: JSON.stringify({ email, code }), // 请求体，传递 email 和 code
    },
  })
}

/**
 * 发送手机验证码
 * @returns
 */
export const getVerificationCodeMobile = (phoneNumber: string) => {
  return useRequest({
    url: ElverifyApi.VERIFY_EL[1],
    options: {
      method: ElverifyApi.VERIFY_EL[0],
      body: JSON.stringify({ phoneNumber }), // 请求体，传递 phoneNumber
    },
  })
}

/**
 * 手机号登录
 * @returns
 */
export const getMobilePhoneLogin = (phoneNumber: string, code: string) => {
  return useRequest({
    url: ELLoginApi.LOGIN_EL[1],
    options: {
      method: ELLoginApi.LOGIN_EL[0],
      body: JSON.stringify({ phoneNumber, code }),
    },
  })
}
/**
 * 修改个人资料
 * @returns
 */
export const getModificationMaterials = (data: ModificationMaterials) => {
  return useRequest({
    url: PersonalDataApi.PERSONA_PD[1],
    options: {
      method: PersonalDataApi.PERSONA_PD[0],
      body: JSON.stringify({ ...data }), // 直接序列化数据
    },
  })
}
